package com.reggie.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * redis 配置类
 */
@Configuration
@Slf4j
public class RedisConfig {

    /**
     *
     * @param redisConnectionFactory redis连接工程
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){

        log.info("开启创建redis模板类.....");
        RedisTemplate redisTemplate = new RedisTemplate();
        //设置redis的Key序列化器
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //设置redis的连接工程
        redisTemplate.setConnectionFactory(redisConnectionFactory);

        return redisTemplate;
    }
}
